package cn.shenlong.portal.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.shenlong.portal.domain.Advertisement;
import cn.shenlong.portal.service.AdvertisementService;


@Controller
@RequestMapping("/adv1/admin")
public class AdvertisementAController {
	
	@Autowired
	private AdvertisementService advertisementService;
	
	
	@RequestMapping("/list")
	public String list(ModelMap mode){
		List<Advertisement> list =  advertisementService.findAllAdv();
		mode.put("list", list);
		
		return "/server/adv/list";
	}
	
	@RequestMapping("/edit")
	public String edit(Integer id,ModelMap mode){
 
		Advertisement adv = advertisementService.findById(id);
		mode.put("adv", adv);
		
		return "/server/adv/edit";
	}
	
	
	@RequestMapping("/update")
	public String update(Advertisement advertisement,ModelMap mode){
		advertisementService.updateAdv(advertisement);

		List<Advertisement> list =  advertisementService.findAllAdv();
		mode.put("list", list);
		
		return "redirect:list.html" ;
	}

}
